<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of button
 *
 * @author Chris Sim
 */

Yii::import('zii.widgets.jui.CJuiInputWidget');

class button extends CJuiInputWidget {
    //put your code here

    public $buttonType = 'button';
    public $button = true;
    public $value = '';
    public $options = array(
                            'icon'=>'',
                            'label'=>'',
                            'text'=>false,
                            );

    public function init() {
        parent::init();
        list($name,$id)=$this->resolveNameID();
        $this->htmlOptions['id']=$id;
        $this->button=false;
	echo CHtml::openTag('div',$this->htmlOptions)."\n";
    }
    public function run() {
        list($name,$id)=$this->resolveNameID();
	$options=empty($this->options) ? '' : CJavaScript::encode($this->options);
        if(!$this->button){
            Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('div#{$id} input[type=\"button\"],div#{$id} a, div#{$id} input[type=\"submit\"]').button($options);");
            echo CHtml::closeTag('div');
        }
        else{
            if(isset($this->htmlOptions['id']))
			$id=$this->htmlOptions['id'];
		else
			$this->htmlOptions['id']=$id;

		if(isset($this->htmlOptions['name']))
			$name=$this->htmlOptions['name'];
		else
			$this->htmlOptions['name']=$name;
            echo CHtml::button($this->value, $this->htmlOptions);
            Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').button($options);");

        }
    }
}
?>
